using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.DirectoryServices;
using System.IO;
using System.Net;
using System.Security.Principal;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Windows.Forms;
using System.Xml;

using DeploymentExt.CrmSdk30;
using Microsoft.Win32;


namespace DeploymentExt
{
   /// <summary>
   /// Supplementary DLL to assist the installer with deployment
   /// </summary>
   [RunInstaller(true)]
   public class QuoteAdvantageInstaller : System.Configuration.Install.Installer
   {
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;

      protected WhoAmIResponse objUserIdentity = null;
      protected string strCrmServiceAddress;
      protected string strCrm30ServiceUrl;
      protected string strCrm40ServiceUrl;
      protected Crm40Installer objCrm40Installer = new Crm40Installer();
      protected int nMajorCrmVersion = 0;
      protected int nMinorCrmVersion = 0;
      protected string strOrganizationName;
      protected MessageWindow msg = new MessageWindow();
      protected string strEmailNotice = "\r\n\r\nIf you need additional assistance, please send email to support@errorfreeorders.com\r\n";

      public QuoteAdvantageInstaller()
      {
         // This call is required by the Designer.
         InitializeComponent();
      }

      /// <summary> 
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if(components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }


      public override void Install(IDictionary savedState)
      {
         try
         {
            base.Install(savedState);
            string   strQuoteAdvantageFolder = this.Context.Parameters["TARGETDIR"];

            if (strQuoteAdvantageFolder[strQuoteAdvantageFolder.Length-1] != '\\')
               strQuoteAdvantageFolder += "\\"; // Make sure the path ends with a trailing slash

            RegistryKey objKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
            string strCrmFolder = objKey.GetValue("WebSitePath").ToString();
            string strQuoteAdvantageWebFolder = strCrmFolder + "\\QuoteAdvantageWeb\\";

            if (MicrosoftCrmIsAvailable())
            {    
               if (this.nMajorCrmVersion > 3)
               {
                  // Microsoft CRM 4.0 Installation
                  objCrm40Installer.PerformInstallation(strCrm40ServiceUrl, strOrganizationName);
                  AdjustWebConfig(strQuoteAdvantageWebFolder);    
                  CopyDataFiles(strQuoteAdvantageWebFolder, strQuoteAdvantageFolder);
                  CreateVirtualDirectory(strQuoteAdvantageWebFolder);
                  RestartIIS();
               }
               else
               {
                  // Microsoft CRM 3.0 Installation
                  AdjustCrmWebConfig(strCrmFolder, strQuoteAdvantageFolder);     
                  AdjustCrmIsvConfig(strCrmFolder, strQuoteAdvantageFolder);     
                  AdjustWebConfig(strQuoteAdvantageWebFolder);    
                  ShowMessage("Updating customizations for Microsoft CRM");
                  ImportCustomCrmAttributes(strQuoteAdvantageFolder);
                  CopyDataFiles(strQuoteAdvantageWebFolder, strQuoteAdvantageFolder);
                  HideMessage();
                  CreateVirtualDirectory(strQuoteAdvantageWebFolder);
                  RestartIIS();
               } 
            }
            else
            {
               throw new ApplicationException("Microsoft CRM was not available. The QuoteAdvantage installation was not successful.");
            }
         }
         catch(Exception ex)
         {
            //     string strMessage = "Installation Failure: " + ex.Message;
            //     MessageBox.Show(strMessage);
            throw ex;
         }
      }


      // Modify the Microsoft CRM web.config file
      private void AdjustCrmWebConfig(string strCrmFolder, string strQuoteAdvantageFolder)
      {
         try
         {
            // Locate the CRM web.config file
            string strWebConfigPath = strCrmFolder + "\\web.config";
             
            // Adjust the ISVIntegration setting in the web.config file
            XmlDocument    docXml = new XmlDocument(); 
            
            docXml.Load(strWebConfigPath);
            XmlNode     nodeRoot = docXml.DocumentElement; 
            XmlNode     nodeAppSettings = docXml.SelectSingleNode("/configuration/appSettings");
            XmlNode     nodeIsvIntegration = nodeAppSettings.SelectSingleNode("add[@key='ISVIntegration']");            
            
            nodeIsvIntegration.Attributes["value"].Value = "All";
            docXml.Save(strWebConfigPath); 
         }
         catch (Exception ex)
         {
            MessageBox.Show("Unable to adjust Microsoft CRM web.config file: " + ex.Message + strEmailNotice);
            MessageBox.Show(ex.StackTrace);
         } 
      } 


      // If there are no QuoteAdvantage XML files in the bin folder, then copy in some new ones
      private void CopyDataFiles(string strQuoteAdvantageWebFolder, string strQuoteAdvantageFolder)
      {
         string strSamplesFolder = strQuoteAdvantageFolder + "Sample Data\\Bicycle\\";
         string strBinFolder = strQuoteAdvantageWebFolder + "\\bin\\";

         if (File.Exists(strBinFolder + "CategoryList.xml") == false)
         {
            File.Copy(strSamplesFolder + "CategoryList.xml", strBinFolder + "CategoryList.xml");
         }

         if (File.Exists(strBinFolder + "BicycleRules.xml") == false)
         {
            File.Copy(strSamplesFolder + "BicycleRules.xml", strBinFolder + "BicycleRules.xml");
         }      
      }
 
      // Modify the ISV settings in the Microsoft CRM web.config file
      private void AdjustCrmIsvConfig(string strCrmFolder, string strQuoteAdvantageFolder)
      {
         try
         {
            // Locate important file paths
            string strSamplesFolder = strQuoteAdvantageFolder + "Sample Data\\Initial Setup\\";
            string strResourcesPath = strCrmFolder + "\\_Resources\\";
            string strIsvConfigPath = strResourcesPath + "isv.config.xml";

            // Locate the CRM web service
            RegistryKey objKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
            string strWebServerUrl = objKey.GetValue("ServerUrl").ToString();
            strWebServerUrl = strWebServerUrl.Replace("MSCRMServices", ""); 
            
            // Update the isv.config.xml file in the _Resources folder
            if (File.Exists(strIsvConfigPath))
            {
               // First, create a backup before we modify it
               File.Copy(strIsvConfigPath, strResourcesPath + "isv.config.xml BACKUP " + DateTime.Now.ToString("MM-dd-yy HH_mm_ss") + ".txt"); 
         
               // Modify the isv.config.xml file
               // The goal is to add the following XML:
               /*
                 <configuration version="3.0.0000.0">
                 .....
                     <Entities>
                        <Entity name="quote">
                              <NavBar ValidForCreate="0" ValidForUpdate="1">
                                 
                                 <NavBarItem Icon="/QuoteAdvantageWeb/QuoteAdvantageSmall.gif" Title="QuoteAdvantage" Url="/QuoteAdvantageWeb/CustomizeQuote.aspx" Id="QuoteAdvantage" AvailableOffline="false" />
                               
                              </NavBar>
                           </Entity>
                     </Entities>   
               */


               XmlDocument    docXml = new XmlDocument(); 
               docXml.Load(strIsvConfigPath);
               XmlNode     nodeRoot = docXml.DocumentElement; 
               XmlNode     nodeEntityList = docXml.SelectSingleNode("/configuration/Entities");
               XmlNode     nodeQuote = nodeEntityList.SelectSingleNode("Entity[@name='quote']");
               XmlNode     nodeQuoteNavBar = null;
               XmlNode     nodeQuoteNavBarItem = null;
               XmlAttribute objAttrib = null;

               if (nodeQuote == null)
               {
                  // Create the node for: <Entity name="quote">
                  nodeQuote = docXml.CreateElement("", "Entity", "");
                  nodeEntityList.AppendChild(nodeQuote);
                  
                  objAttrib = docXml.CreateAttribute("", "name", "");
                  objAttrib.Value = "quote";
                  nodeQuote.Attributes.Append(objAttrib);
               }
    
               nodeQuoteNavBar = nodeQuote.SelectSingleNode("NavBar");

               if (nodeQuoteNavBar == null)
               {
                  // Create the node for: <NavBar ValidForCreate="0" ValidForUpdate="1">
                  nodeQuoteNavBar = docXml.CreateElement("", "NavBar", "");
                  nodeQuote.AppendChild(nodeQuoteNavBar);
                  
                  objAttrib = docXml.CreateAttribute("", "ValidForCreate", "");
                  objAttrib.Value = "0";
                  nodeQuoteNavBar.Attributes.Append(objAttrib);
                  
                  objAttrib = docXml.CreateAttribute("", "ValidForUpdate", "");
                  objAttrib.Value = "1";
                  nodeQuoteNavBar.Attributes.Append(objAttrib);
               }

               nodeQuoteNavBarItem = nodeQuoteNavBar.SelectSingleNode("NavBarItem[@Title='QuoteAdvantage']");
                
               if (nodeQuoteNavBarItem == null)
               {             
                  nodeQuoteNavBarItem = CreateNavBarItem(docXml, strWebServerUrl);
                  nodeQuoteNavBar.AppendChild(nodeQuoteNavBarItem);
               }    
               else
               {
                  nodeQuoteNavBarItem.Attributes["Icon"].Value = strWebServerUrl + "QuoteAdvantageWeb/QuoteAdvantageSmall.gif";
                  nodeQuoteNavBarItem.Attributes["Url"].Value = strWebServerUrl + "QuoteAdvantageWeb/CustomizeQuote.aspx";
               }
               
               docXml.Save(strIsvConfigPath);  
            }
            else
            {
               // There is no existing isv.config.xml file. We can just copy our new one into place
               AdjustSampleIsvConfig(strSamplesFolder);

               // Copy the new file into place
               File.Copy(strSamplesFolder + "isv.config.xml", strResourcesPath + "isv.config.xml"); 
            }

         }
         catch (Exception ex)
         {
            MessageBox.Show("Unable to adjust Microsoft CRM isv.config file: " + ex.Message);
            MessageBox.Show(ex.StackTrace);
         } 
      }

      // Create the XML for:                                  
      //   <NavBarItem Icon="/QuoteAdvantageWeb/QuoteAdvantageSmall.gif" Title="QuoteAdvantage" Url="/QuoteAdvantageWeb/CustomizeQuote.aspx" Id="QuoteAdvantage" AvailableOffline="false" />
      private XmlNode CreateNavBarItem(XmlDocument docXml, string strWebServerUrl)
      {
         XmlNode nodeQuoteNavBarItem = null;
         XmlAttribute objAttrib = null;

         nodeQuoteNavBarItem = docXml.CreateElement("", "NavBarItem", "");
               
         objAttrib = docXml.CreateAttribute("", "Icon", "");
         objAttrib.Value = strWebServerUrl + "QuoteAdvantageWeb/QuoteAdvantageSmall.gif";
         nodeQuoteNavBarItem.Attributes.Append(objAttrib);
                  
         objAttrib = docXml.CreateAttribute("", "Title", "");
         objAttrib.Value = "QuoteAdvantage";
         nodeQuoteNavBarItem.Attributes.Append(objAttrib);
                  
         objAttrib = docXml.CreateAttribute("", "Url", "");
         objAttrib.Value = strWebServerUrl + "QuoteAdvantageWeb/CustomizeQuote.aspx";
         nodeQuoteNavBarItem.Attributes.Append(objAttrib);
                  
         objAttrib = docXml.CreateAttribute("", "Id", "");
         objAttrib.Value = "QuoteAdvantage";
         nodeQuoteNavBarItem.Attributes.Append(objAttrib);
                  
         objAttrib = docXml.CreateAttribute("", "AvailableOffline", "");
         objAttrib.Value = "false";
         nodeQuoteNavBarItem.Attributes.Append(objAttrib);

         return nodeQuoteNavBarItem;
      }
 
      private void AdjustSampleIsvConfig(string strSamplesFolder)
      {
         try
         {   
            // Load the isv.config file
            string strIsvConfigPath = strSamplesFolder + "\\isv.config.xml";
            XmlDocument    docXml = new XmlDocument(); 
            docXml.Load(strIsvConfigPath);
            XmlNode     nodeRoot = docXml.DocumentElement; 
            XmlNode     nodeQuoteNav = docXml.SelectSingleNode("/configuration/Entities/Entity[@name='quote']/NavBar/NavBarItem");
                                   
            // Locate the CRM web service
            RegistryKey objKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
            string strWebServerUrl = objKey.GetValue("ServerUrl").ToString();
            
            strWebServerUrl = strWebServerUrl.Replace("MSCRMServices", ""); 
            nodeQuoteNav.Attributes["Icon"].Value = strWebServerUrl + "QuoteAdvantageWeb/QuoteAdvantageSmall.gif";
            nodeQuoteNav.Attributes["Url"].Value = strWebServerUrl + "QuoteAdvantageWeb/CustomizeQuote.aspx";
            
            docXml.Save(strIsvConfigPath);
         }
         catch (Exception ex)
         {
            MessageBox.Show("Unable to save changes to the sample isv.config.xml file: " + ex.Message + strEmailNotice);
         }      
      }

      // Adjust the QuoteAdvantage web.config file
      private void AdjustWebConfig(string strQuoteAdvantageWebFolder)
      {
         try
         {   
            // Load the web.config file
            string strWebConfigPath = strQuoteAdvantageWebFolder + "\\web.config";
            XmlDocument    docXml = new XmlDocument(); 
            docXml.Load(strWebConfigPath);
            XmlNode     nodeRoot = docXml.DocumentElement; 
            XmlNode     nodeAppSettings = docXml.SelectSingleNode("/configuration/appSettings");
                       
            // Adjust the URL for the web service
            XmlNode     nodeServerName = nodeAppSettings.SelectSingleNode("add[@key='QuoteAdvantage.CrmSdk.CrmService']");
            
            if (nodeServerName == null)
            {
               if (nodeAppSettings == null)
               {
                  MessageBox.Show("Unable to load <appSettings> node from web.config file");
               }
               else
               {
                  nodeServerName = docXml.CreateElement("", "add", "");
                  XmlAttribute objKeyAttrib = docXml.CreateAttribute("", "key", "");
                  objKeyAttrib.Value = "QuoteAdvantage.CrmSdk.CrmService";

                  XmlAttribute objValueAttrib = docXml.CreateAttribute("", "value", "");
                  objValueAttrib.Value = strCrm30ServiceUrl;

                  nodeServerName.Attributes.Append(objKeyAttrib);
                  nodeServerName.Attributes.Append(objValueAttrib);

                  nodeAppSettings.AppendChild(nodeServerName);
               }
            }
            else
            {
               nodeServerName.Attributes["value"].Value = strCrm30ServiceUrl;
            }  

            docXml.Save(strWebConfigPath);
         }
         catch (Exception ex)
         {
            MessageBox.Show("Unable to adjust web.config file: " + ex.Message + strEmailNotice);
         } 
      }
            
      private string FindCrmWebAddress()
      {
         // Locate the CRM web service
         RegistryKey objKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");

         if (objKey != null)
         {
            object objRegistryValue = objKey.GetValue("ServerUrl");

            if (objRegistryValue != null)
            {
               strCrmServiceAddress = objRegistryValue.ToString();
               strCrm30ServiceUrl = strCrmServiceAddress + "/2006/CrmService.asmx";
               strCrm40ServiceUrl = strCrmServiceAddress + "/2007/CrmService.asmx";
            }
         }

         return strCrm30ServiceUrl;
      }

      private bool MicrosoftCrmIsAvailable()
      {
         bool  bResult = false;
         bool  bDone = false;

         while (!bDone)
         {
            bResult = VerifyCrmWebService();

            if (bResult)
            {
               bDone = true;  // We successfully connected to the 3.0 web service
               GetCrmVersion();
            }
            else
            {
               DialogResult   dlgResult = MessageBox.Show("The Microsoft CRM Web Service is not available. Please make sure that Microsoft CRM is running on this server.", "QuoteAdvantage Installation", MessageBoxButtons.RetryCancel);
               if (dlgResult == DialogResult.Cancel)
               {
                  bDone = true;  // We're giving up
               }
            }
         }

         return bResult;
      }

      private bool GetCrmVersion()
      {
         bool bResult = true;
         Crm40Installer objInstaller = new Crm40Installer();

         strOrganizationName = GetOrganizationName();
         bResult = objInstaller.GetCrmVersion(strCrm40ServiceUrl, strOrganizationName);
         
         if (bResult)
         {
            nMajorCrmVersion = objInstaller.MajorCrmVersion;
            nMinorCrmVersion = objInstaller.MinorCrmVersion;
         }
         else
         {
            // If the Microsoft CRM 4.0 web APIs do not respond then assume that this is version 3.0
            nMajorCrmVersion = 3;
            nMinorCrmVersion = 0;
            bResult = true;
         }
         
         return bResult;
      }

      private string GetOrganizationName()
      {
         string strName = "";
         
         try
         {
            CrmService  objService = new CrmService();
            
            objService.Url = strCrm30ServiceUrl;
            objService.Credentials = objCrm40Installer.GetCredentials(strCrm30ServiceUrl);
            TargetRetrieveBusinessUnit targetGetBusinessUnit = new TargetRetrieveBusinessUnit();
            targetGetBusinessUnit.EntityId = objUserIdentity.BusinessUnitId;
            RetrieveRequest getBusinessUnit = new RetrieveRequest();
            getBusinessUnit.Target = targetGetBusinessUnit;
            getBusinessUnit.ColumnSet = new AllColumns();
            RetrieveResponse businessUnitResponse = (RetrieveResponse)objService.Execute(getBusinessUnit);
            businessunit objBusinessUnit = (businessunit)businessUnitResponse.BusinessEntity;
         
            ColumnSet objColumns = new ColumnSet();
            objColumns.Attributes = new string[] {"currencyformatcode", "currencysymbol", "organizationid", "name"};
            organization objCrmOrganization = (organization)objService.Retrieve(EntityName.organization.ToString(), objBusinessUnit.organizationid.Value, objColumns);
         
            if (objCrmOrganization != null)
            {
               strName = objCrmOrganization.name;
            }
         }
         catch (Exception ex)
         {
            MessageBox.Show("Error while retrieving CRM Organization Name: " + ex.Message);
         }

         return strName;     
      }

      private void ShowMessage(string strMessage)
      {
         msg.Message = strMessage;
         msg.Show();
         msg.BringToFront();
         msg.Update();
      }

      private void HideMessage()
      {
         msg.Hide();
      }

      // Check to make sure that we can talk to Microsoft CRM
      private bool VerifyCrmWebService()
      {     
         ShowMessage("Connecting to Microsoft CRM");
         bool        bResult = true;
         CrmService  objService = new CrmService();

         try
         {
            FindCrmWebAddress();
            objService.Url = strCrm30ServiceUrl;
            objService.Credentials = objCrm40Installer.GetCredentials(strCrm30ServiceUrl);

            // Create the request object.
            WhoAmIRequest userRequest = new WhoAmIRequest();

            // Execute the request.
            objUserIdentity = (WhoAmIResponse) objService.Execute(userRequest);         
         }
         catch (Exception ex)
         {
            MessageBox.Show("Unable to establish communication with the Microsoft CRM Web Service:\r\n" + ex.Message + strEmailNotice);
            bResult = false;
         }

         HideMessage();

         return bResult;
      }

      // Use the CRM 3.0 web service to import and publish the database customizations
      void ImportCustomCrmAttributes(string strQuoteAdvantageFolder)
      {
         CrmService objService = new CrmService();

         objService.Url = strCrm30ServiceUrl;
         objService.Credentials = System.Net.CredentialCache.DefaultCredentials;

         try
         {
            // Import customizations
            ImportXmlRequest objImportRequest = new ImportXmlRequest(); 
         
            string strSamplesFolder = strQuoteAdvantageFolder + "Sample Data\\Initial Setup\\";
            string strFileName = strSamplesFolder + "QuoteAdvantageCustomizations.xml";
            StreamReader xmlfile = new StreamReader(strFileName);
            string   strXml = xmlfile.ReadToEnd();

            // Tell the request we are importing the QuoteDetail entity
            objImportRequest.ParameterXml = @"<importexportxml>
                                             <entities>
                                                <entity>quotedetail</entity>
                                             </entities>
                                          <nodes/>
                                        </importexportxml>";

            objImportRequest.CustomizationXml = strXml;

            ImportXmlResponse importResponse = (ImportXmlResponse)objService.Execute(objImportRequest);
         }
         catch (SoapException ex)
         {
            string strMessage = ex.Detail.InnerText;

            if (strMessage.IndexOf("privilege") != -1)
            {
               MessageBox.Show("QuoteAdvantage can only be installed by a user with Administrative privileges inside of Microsoft CRM. \r\n\r\n" + strMessage + strEmailNotice);
            }
            else
            {
               MessageBox.Show("Failure while importing CRM customizations: " + ex.Detail.InnerText);
               MessageBox.Show(ex.StackTrace);
            }
         }
         catch (Exception ex)
         {
            MessageBox.Show("Failure while importing CRM customizations: " + ex.Message);
            MessageBox.Show(ex.StackTrace);
         }

         try
         {
            // Publish customizations
            PublishXmlRequest objPublishRequest = new PublishXmlRequest();
            objPublishRequest.ParameterXml = @"<importexportxml>
                                                   <entities>
                                                      <entity>quotedetail</entity>
                                                   </entities>
                                                   <nodes/>
                                                </importexportxml>";
            PublishXmlResponse response = (PublishXmlResponse)objService.Execute(objPublishRequest);
         }
         catch (Exception ex)
         {
            MessageBox.Show("Failure while publishing CRM customizations: " + ex.Message);
            MessageBox.Show(ex.StackTrace);
         }
      }

      public void RestartIIS()
         {
         RestartWebServerForm  frmRestart = new RestartWebServerForm();

         frmRestart.ShowDialog();
         if (frmRestart.Result == true)
         {
            try
            {
               ShowMessage("Please wait. Restarting IIS...");
               Process objIISReset = new Process();
               objIISReset.StartInfo.FileName = "iisreset.exe";
               objIISReset.StartInfo.CreateNoWindow = true;
               objIISReset.StartInfo.RedirectStandardOutput = true;
               objIISReset.StartInfo.UseShellExecute = false;
               objIISReset.Start();
               objIISReset.WaitForExit();
            }
            catch (Exception ex)
            {
               MessageBox.Show("Error restarting IIS: " + ex.Message);
            }
         }
      }
      
      public void CreateVirtualDirectory(string strQuoteAdvantageWebFolder)
      {
         try
         {
            RegistryKey objKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
            string strWebsiteName = objKey.GetValue("website").ToString();
            string[] objPathList = strWebsiteName.Split('/');
            string strWebServerNumber = objPathList[objPathList.Length-1];
            int nWebServerNumber = Convert.ToInt32(strWebServerNumber);         

            CreateNewVirtualDirectory(nWebServerNumber, "QuoteAdvantageWeb", strQuoteAdvantageWebFolder, true);
         }
         catch (Exception ex)
         {
            MessageBox.Show("Error creating virtual directory: " + ex.Message);
         }
      }

      public void CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, bool AccessScript)
      {
         DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
         DirectoryEntry NewVirtualDir;
         bool  bFound = false;

         // Check for existing entry
         foreach (DirectoryEntry entry in Parent.Children)
         {
            if (entry.Name == VirtualDirName)
               bFound = true;
         }
         
         if (!bFound)
         {
            NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir");
            NewVirtualDir.Properties["Path"][0] = Path;
            NewVirtualDir.Properties["AccessScript"][0] = AccessScript;
            NewVirtualDir.Properties["AppFriendlyName"][0] = VirtualDirName;
            NewVirtualDir.Properties["AppIsolated"][0] = 2;
            NewVirtualDir.Properties["AppRoot"][0] = "/LM/W3SVC/" + ServerId + "/Root/" + VirtualDirName;
            NewVirtualDir.CommitChanges();     
         }
      }
      

      #region Component Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         components = new System.ComponentModel.Container();
      }
      #endregion
   }
}
